package com.imooc.spark.streaming.operateTest

import org.apache.spark.SparkConf
import org.apache.spark.streaming.{Seconds, StreamingContext}

/**
  * http://spark.apache.org/docs/latest/streaming-programming-guide.html#transformations-on-dstreams
  * 通过将源DStream的每个元素传递给函数func来返回一个新的DStream 。
  * @description map(func) 操作
  * @author yuyon26@126.com
  * @date 2018/10/24 10:19
  */
object Map {
  def main(args: Array[String]): Unit = {

    val sparkConf = new SparkConf().setMaster("local[2]").setAppName("NetworkWordCount")
    val ssc = new StreamingContext(sparkConf, Seconds(5))
    ssc.sparkContext.setLogLevel("ERROR")

    val lines = ssc.socketTextStream("192.168.31.30", 9999)
    val mapLines = lines.map(word => "map_" + word)

    mapLines.print()

    ssc.start()
    ssc.awaitTermination()
  }
}
